<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>DFC</title>
		<link rel="shortcut icon" href="img/favicon.ico">
		<link rel="stylesheet" href="css/intlTelInput.min.css">
		<link rel="stylesheet" href="css/index.css">
		<link rel="stylesheet" href="css/register.css" />

		<script src="js/jquery.min.js"></script>

		<style>
			
    </style>

	</head>

	<body>

		<div id="register">
			
			<div class="centent_reg">
				<div class="logo">
					<img class="login_img_reg" src="img/logo.png" alt="" />
				</div>
				<div class="input_div">
					<ul>
						<li>
							<div>
								<input id="mobile" name="phone" type="tel" placeholder="请输入手机号">
							</div>
						</li>
						<li>
							<input type="text" id="valid_code" placeholder="请输入验证码" />
							<button id="generate_code" class="reg_ver_but">获取验证码</button>
						</li>
						<li>
							<input type="password" id="pwd" placeholder="请输入密码" />
						</li>
						<li>
							<input type="text" disabled="disabled" id="invited_code" placeholder="请输入邀请码" />
						</li>
						<li></li>
					</ul>
				</div>
				<div class="w_100b reg_but_div">
					<button class="reg_but" id="reg_btn">注册</button>
				</div>
				<div class="w_100b reg_but_div" style="margin-top: 15px;">
					<button class="reg_but" id="download_btn">下载</button>
				</div>
			</div>
		</div>
		<script src="js/vue.js"></script>
		<script src="js/intlTelInput.min.js"></script>
		<script src="js/vue-i18n.min.js"></script>
		<script src="js/lang/zh.js"></script>
		<script src="js/lang/en.js"></script>
		<script src="js/lang/ko.js"></script>
		<script src="js/lang/tw.js"></script>
		<script type="text/javascript">
			var input = document.querySelector("#mobile");
			window.intlTelInput(input, {
				// allowDropdown: false,
				// autoHideDialCode: false,
				// autoPlaceholder: "off",
				dropdownContainer: document.body,
				// excludeCountries: ["us"],
				// formatOnDisplay: false,
				// geoIpLookup: function(callback) {
				//   $.get("http://ipinfo.io", function() {}, "jsonp").always(function(resp) {
				//     var countryCode = (resp && resp.country) ? resp.country : "";
				//     callback(countryCode);
				//   });
				// },
				// hiddenInput: "full_number",
				// initialCountry: "auto",
				// localizedCountries: { 'de': 'Deutschland' },
				// nationalMode: false,
				// onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
				// placeholderNumberType: "MOBILE",
				preferredCountries: ['cn', 'us'],
				separateDialCode: true,
				utilsScript: "js/utils.js",
			});
			// const i18n = new VueI18n({
			//     locale: 'zh', // 语言标识
			//     messages: {
			//         zh: zh_language,
			//         ko: ko_language,
			//         en: en_language,
			//         tw: tw_language
			//     }
			// });


			// var vm = new Vue({
			//     el:'#register',
			//     i18n,
			//     data:{
			//         language:'',
			//         telNumber:''
			//     },
			//     watch:{
			//         language:function (nval,oval) {
			//             console.log(nval + '/' + oval);
			//             switch (nval)
			//             {
			//                 case '':
			//                     this.$i18n.locale = 'zh';
			//                     break;
			//                 case '简体中文':
			//                     this.$i18n.locale = 'zh';
			//                     break;
			//                 case '韩文':
			//                     this.$i18n.locale = 'ko';
			//                     break;
			//                 case '英文':
			//                     this.$i18n.locale = 'en';
			//                     break;
			//                 case '繁体中文':
			//                     this.$i18n.locale = 'tw';
			//                     break;
			//             }
			//         }
			//     }
			// });


			// $("#mobile").intlTelInput();


			$(document).ready(function() {
				var W = window.screen.width - 40;
				$(".country-list").width(W - 2);
			});

			$("#download_btn").click(function() {
				window.location.href = 'index.html';
			});

			$(function() {
				var baseUrl = 'http://akbmining.club/akbm_dfc';
				var invited_code = getUrlParam('avatar');
				if (invited_code) {
					$("#invited_code").val(getUrlParam('avatar'));
				} else {
					$("#invited_code").val('000000');
				}

				function getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
					var r = window.location.search.substr(1).match(reg);
					if (r != null) return unescape(r[2]);
					return null;
				}

				function CommonException(message, code) {
					this.message = message;
					this.code = code;
				}

				function check_input(phone, valid_code, pwd) {
					if (telNumber === "" || telNumber.length !== 11) {
						throw new CommonException("手机号码为空，或小于11位", 1);
					}
					if (valid_code.val() === "") {
						throw new CommonException("验证码为空", 2);
					}
					if (pwd.val() === "") {
						throw new CommonException("密码为空", 3);
					}
					/* if (avatar_code.val() === "" ) {
					    throw new CommonException("邀请码为空", 4);
					} */
				}


				//点击注册
				$("#reg_btn").click(function() {
					var area = $(".iti__selected-dial-code").text();
					var Numarea=area.slice(1);
					// console.log($("#mobile").val());
					if ($("#mobile").val() !== '') {
						telNumber = $("#mobile").val();
					}
					// console.log(telNumber);
					try {
						check_input($("#mobile"), $("#valid_code"), $("#pwd"));
						console.log(telNumber);
						console.log($("#valid_code").val());
						console.log($("#pwd").val());
						console.log($("#invited_code").val());
						//验证输入的验证码
						
						
						$.ajax({
							type: "POST",
							url: baseUrl + "/cbt/addUserByPhone",
							data: {
								phone: telNumber,
								passWord: $("#pwd").val(),
								avatar: $("#invited_code").val(),
								code: $("#valid_code").val(),
								area:Numarea
							},
							dataType: "json",
							async: false,
							success: function(data) {
								console.log(data);
								var result_json = eval(data);
								//判断是否成功
								if (result_json.code !== 100) {
									alert(result_json.message);
								} else {
									window.location.href = 'index.html';
								}
							},
							error: function(err) {
								console.log(err);
							}
						});
					} catch (e) {
						alert(e.message)
					}
				});
				//点击发送验证码
				$("#generate_code").click(function() {
					var telNumber = $("#mobile").val();
					var disabled = $("#generate_code").attr("disabled");
					var area = $(".iti__selected-dial-code").text();
					var Numarea=area.slice(1);
					if (disabled) {
						return false;
					}
					if (telNumber === "" || isNaN(telNumber) || telNumber.length !== 11) {
						alert("请填写正确的手机号！");
						return false;
					} else {
						$.ajax({
							type: "POST",
							url: baseUrl + "/cbt/sendPhoneMsg",
							data: {
								phone: telNumber,
								type: 1,
								code: Numarea
							},
							dataType: "json",
							async: false,
							success: function(data) {
								console.log(data);
								var result_json = eval(data);
								//判断是否成功
								if (result_json.code !== 100) {
									alert(result_json.message);
								} else {
									send_code($("#generate_code"));
								}
							},
							error: function(err) {
								console.log(err);
							}
						});
					}
				});

				var clock = '';
				var nums = 60;

				function send_code() {
					$("#generate_code").attr("disabled", true);
					$("#generate_code").text(nums + " S");
					clock = setInterval(doLoop, 1000); //一秒执行一次
				}

				function doLoop() {
					nums--;
					if (nums > 0) {
						$("#generate_code").attr("disabled", true);
						$("#generate_code").text(nums + " S");
					} else {
						clearInterval(clock); //清除js定时器
						$("#generate_code").attr("disabled", false);
						$("#generate_code").text("发送验证码");
						nums = 60; //重置时间
					}
				}
			})
		</script>
	</body>

</html>
